#include "head_2.h"

extern int msgid;
extern char dev_camera_mask;
extern pthread_mutex_t mutex_camera;
extern pthread_cond_t cond_camera;
extern void buzzer_open();
extern void buzzer_close();


void *pthread_client_request() {
	
	struct msg msgtxt;
	printf("%d\n",__LINE__);
	while(1){
		if (msgrcv(msgid,(void *)&msgtxt,sizeof(struct msg) - sizeof(long),1L,0) < 0)
		{
			perror("fail to msgrcv");
			exit(1);
		}

		switch(msgtxt.text) {
		case 32:		//关闭操纵
			system("echo 1 > /sys/class/leds/led2/brightness");
			break;
		case 33:		//打开操作
			system("echo 0 > /sys/class/leds/led2/brightness");
			printf("%d\n",__LINE__);
			break;
		case 34:		//close
			system("echo 1 > /sys/class/leds/led3/brightness");
			break;
		case 35:		//打开操作
			system("echo 0 > /sys/class/leds/led3/brightness");
			break;
		case 17:
			buzzer_open();
			break;
		case 16:
			buzzer_close();
		case 1:
			printf("case:%d\n",__LINE__);
			pthread_mutex_lock (&mutex_camera);
			dev_camera_mask = msgtxt.text;
			printf("%d\n",dev_camera_mask);
			pthread_cond_signal (&cond_camera);
			pthread_mutex_unlock (&mutex_camera);
			break;
		case 3:	
			pthread_mutex_lock (&mutex_camera);
			dev_camera_mask = msgtxt.text;
			pthread_cond_signal (&cond_camera);
			pthread_mutex_unlock (&mutex_camera);
			break;

		}
	}
}
